package es.ibm.santillana.mdm.postsave.catalog;



import java.io.IOException;

import com.ibm.pim.catalog.item.Item;
import com.ibm.pim.context.Context;
import com.ibm.pim.context.PIMContextFactory;
import com.ibm.pim.extensionpoints.PostItemSaveFunctionArguments;

import es.ibm.santillana.mdm.integration.ChangesHandler;
import es.ibm.santillana.mdm.integration.ExportData;
import es.ibm.santillana.mdm.integration.IntegrationChanges;


public class MaestroArticulosPostSave extends CatalogGenericPostSave {

	public MaestroArticulosPostSave() {
		// TODO Auto-generated constructor stub
	}

	public void postsave(PostItemSaveFunctionArguments arg0) {
		super.postsave(arg0);
		
		//get object to use in post save
		Item itm = arg0.getItem();
		Context ctx = PIMContextFactory.getCurrentContext();
		
		//Export item to Broker
		ChangesHandler changes = new ChangesHandler(itm,itm.getCatalog().getName(), itm.getPrimaryKey(), ctx);
		changes.createChanges();
		try {
			ExportData exportData = new ExportData();
			exportData.exportXML(changes.getIntegrationChanges());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		super.finishPostsave(arg0);
	}

	
	
}
